﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

using KorbeRTR.Models;

namespace KorbeRTR.MES.Requests
{
    public class SendEquimentBase
    {
        public static async Task Get(FormTestMES form = null)
        {
            var client = HttpClientHelper.GetInstance();

            string url = HttpClientHelper.Url + "SendEquimentBase";

            var root = ProtocolHelper.CreateFrame();
            root["Mac"] = "";

            url += "?dat=" + root.ToString(Formatting.None);

            var RequestMessage = new HttpRequestMessage(HttpMethod.Get, url);

            form?.SetRequest(url);

            var ResponseMessage = await client.SendAsync(RequestMessage);
            var response = await ResponseMessage.Content.ReadAsStringAsync();

            form?.SetResponse(response);


            {
                var gl = Global.GetInstance();

                var op = new OperationRecord
                {
                    Time = DateTime.Now,
                    User = gl.CurrentUser != null ? gl.CurrentUser.UserName : "System",
                    OperationType = "MES",
                    Operation = root.ToString() + Environment.NewLine + response
                };

                OperationRecord.Add(op);
            }
        }
    }
}
